package com.zgjkhis.modules.system.service.impl;

import com.github.pagehelper.PageInfo;
import com.zgjkhis.common.service.impl.BaseServiceImpl;
import com.zgjkhis.common.utils.QueryHelpPlus;
import com.zgjkhis.domain.PageResult;
import com.zgjkhis.dozer.service.IGenerator;
import com.zgjkhis.modules.system.domain.Supplier;
import com.zgjkhis.modules.system.service.SupplierService;
import com.zgjkhis.modules.system.service.dto.SupplierDto;
import com.zgjkhis.modules.system.service.dto.SupplierQueryCriteria;
import com.zgjkhis.modules.system.service.mapper.SupplierMapper;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;

/**
 * @Author yzq
 * @Description 供应商
 * @Date 2021/6/23 9:47
 * @Param
 * @return
 **/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "user")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class SupplierServiceImpl extends BaseServiceImpl<SupplierMapper, Supplier> implements SupplierService {

    private final IGenerator generator;

    @Override
    public PageResult<SupplierDto> queryAll(SupplierQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<Supplier> page = new PageInfo<>(queryAll(criteria));
        return PageResult.data(page, SupplierDto.class);
    }

    @Override
    //@Cacheable
    public List<Supplier> queryAll(SupplierQueryCriteria criteria){
        List<Supplier> supplierList = baseMapper.selectList(QueryHelpPlus.getPredicate(Supplier.class, criteria));
        return supplierList;
    }

    @Override
    public SupplierDto findDetailById(String id) {
        Supplier supplier=this.getById(Long.valueOf(id));
        return generator.convert(supplier, SupplierDto.class);
    }
}
